#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
# @Time    : 2024/9/30 14:21 
# @Author  : SumKids 
# @Site    :  
# @File    : 03_程序启动加载页面.py
# @Software: PyCharm
# @Description:
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QPushButton
from PySide6.QtCore import Qt, QTimer
from PySide6.QtGui import QPixmap, QFont


class LoadingWidget(QWidget):
    def __init__(self):
        super().__init__()
        # 隐藏默认的标题栏
        self.setWindowFlag(Qt.WindowType.FramelessWindowHint)
        # 剔除边框或padding等样式
        self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)

        self.pixmap = QPixmap('../ui/pic/v2-8d4b5193cf321013e531229ab558b48b_r.jpg') \
            .scaled(800, 800, Qt.AspectRatioMode.KeepAspectRatio)
        self.loading_pic = QLabel()
        self.loading_pic.setPixmap(self.pixmap)
        # self.loading_pic.setAlignment(Qt.AlignmentFlag.AlignCenter)
        # self.loading_pic.setScaledContents(True)

        layout = QVBoxLayout()
        layout.addWidget(self.loading_pic)
        self.setLayout(layout)

        # 使用QTimer 模仿数据加载
        QTimer.singleShot(3000, self.openMainWindow)

    def openMainWindow(self):
        self.close()
        self.main_window = MainWindow()
        self.main_window.show()


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        lable = QLabel('这是主窗口')
        lable.setFont(QFont('微软雅黑', 40))

        layout = QVBoxLayout()
        layout.addWidget(lable)
        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication()
    window = LoadingWidget()
    window.show()
    app.exec()
